var vueApp = new Vue({
  el: '#app',
  data: function () {
    return {
    	  createDate:[],
    	  msgType:'',
    	  read_status:'',
    	  title:'',
    	  mtpOptions:[],
    	  mstOptions:[],
    	  msgData:[],
    	  currentPageNbr: config.currentPageNbr,
          pageSizes: config.pageSizes,
          pageSize: config.defaultpageSize,
          totalRecords: 0,
          addUrl:'msgadd.html',
          readUrl:'msgread.html',
          comDel:false,          
          curId:''
      };
  },
  mounted: function () {
    this.initData();

  },
  methods: {
    initData:function(){
       var that = this;
       this.createDate.push(tools.getQueryString("beginDate")==""?util.addMonth(new Date(),-1):new Date(tools.getQueryString("beginDate").replace(/-/g,"/")));
       this.createDate.push(tools.getQueryString("endDate")==""?new Date():new Date(tools.getQueryString("endDate").replace(/-/g,"/")));
       this.mtpOptions.push({"code":"-1","code_desc":"请选择","display_order":"0"});
       this.mtpOptions.push.apply(this.mtpOptions,msg_type);
       this.msgType = tools.getQueryString("msgType")==""?"-1":tools.getQueryString("msgType");
       this.mstOptions.push({"code":"-1","code_desc":"请选择","display_order":"0"});
       this.mstOptions.push.apply(this.mstOptions,read_status);
       
//       var read_status=[{"code":"read_status_0","code_desc":"未阅读","dict_name":"read_status","display_order":"1","remarks":""},{"code":"read_status_1","code_desc":"已阅读","dict_name":"read_status","display_order":"2","remarks":""}];
       this.read_status = tools.getQueryString("read_status")==""?"read_status_0":tools.getQueryString("read_status");   // 已阅读  未阅读
  	   
       this.title=tools.getQueryString("title");
//       userEx.getUserInfo(function(data){
//            that.user_ssbm = data.userinfo.deptCode; 
//         
//            tools.checkPriv(data.userinfo.privNames,"cbgs");
//           
//       });
//       tools.checkPriv(userExInfo.privNames,"cbgs"); 

       this.onSearch();
       
    },

  	
    titleLink:function(row){
    	var beginDate = this.createDate!=null?util.formatTime(this.createDate[0],'yyyy-MM-dd'):"";
        var endDate = this.createDate!=null?util.formatTime(this.createDate[1],'yyyy-MM-dd'):"";
        window.location.href = this.addUrl+"?msgId="+ row.msg_id+"&msgType="+this.msgType+"&read_status="
        +this.read_status+"&title="+this.title+"&beginDate="+beginDate+"&endDate="+endDate+"&oper=read&org=1"; 
    },
    
    rpyMsg:function(row){
    	var beginDate = this.createDate!=null?util.formatTime(this.createDate[0],'yyyy-MM-dd'):"";
        var endDate = this.createDate!=null?util.formatTime(this.createDate[1],'yyyy-MM-dd'):"";
    	window.location.href = this.readUrl+"?detailId="+row.detail_id+"&msgType="+this.msgType+"&read_status="
        +this.read_status+"&title="+this.title+"&beginDate="+beginDate+"&endDate="+endDate;
    },
    
    onSearch:function(){
      var that = this;
      var beginDate = this.createDate!=null?util.formatTime(this.createDate[0],'yyyy-MM-dd'):"";
      var endDate = this.createDate!=null?util.formatTime(this.createDate[1],'yyyy-MM-dd'):"";
      var jso = {
    		"startDate": beginDate,
    		"endDate": endDate,
    		"msgType": this.msgType,    		
    		"read_status":this.read_status,
    		"msg_title": this.title
      };
      var postdata = {
    	    "jsonStr":JSON.stringify(jso),    		 
            "currentPageNbr" : this.currentPageNbr,
            "pageSize" : this.pageSize
      };
      
      tools.ajaxRequestAsyncEx("pub/msg/revMessageList",postdata, function(data){
          if (data.respCode == "0") {
        	  console.log(data);
              that.msgData = data.list;
              that.totalRecords = data.page.totalRecords;       
          } else {
              that.msgData = [];
              that.totalRecords =0;
              that.currentPageNbr=1;
              that.showError(data.respDesc);      
          }
      });


    },
    search:function(){
    	this.currentPageNbr = 1;
        this.onSearch();
    },
    handleSizeChange:function(pageSize){
        this.pageSize = pageSize;
        this.currentPageNbr = 1;
        this.onSearch();
    },

    handleCurrentChange:function(currentPageNbr){
      this.currentPageNbr = currentPageNbr;
      this.onSearch();
    },

    showError: function(info){
        var i = (info==undefined?"加载数据错误":info);
        this.$alert(i, '系统错误', {
             confirmButtonText: '确定'
        }); 
    },

  },
  watch:{
//      currentPageNbr : function() {
//          // alert(this.currentPageNbr);
//          this.onSearch();
//      },
//        
//      pageSize : function() {
//          // alert(this.currentPageNbr);
//    	  if(this.currentPageNbr=="1"){
//    		  this.onSearch();
//    	  }else{
//    		  this.currentPageNbr=="1";
//    	  }         
//      },
  }
})